package types

import (
	"strings"
)

type Err struct {
	// XMLName xml.Name `xml:"err"`

	*Object `xml:",omitempty"`
}

func (e *Err) Error() string {
	var buf strings.Builder
	if e != nil && e.Object != nil {
		if e.Display != "" {
			buf.WriteString(e.Display)
		}
		if e.DisplayName != "" {
			buf.WriteByte(',')
			buf.WriteString(e.DisplayName)
		}
		for _, v := range e.Object.Errs {
			if v != nil {
				if s := v.Error(); s != "<nil>" {
					buf.WriteByte(',')
					buf.WriteString(s)
				}
			}
		}
	}
	if buf.Len() > 0 {
		return buf.String()
	}
	return "<nil>"
}
